package com.PinZhuo.www;

import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;
import com.PinZhuo.www.shouye.HomeFragment;
import com.PinZhuo.www.zhuodan.ZhuoDanFragment;
import com.utils.ImageUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tukela on 2015/10/10.
 */
public class HomeActivity extends BaseActivity implements View.OnClickListener {

    private TextView textView_Shouye, textView_Zhuodan,textView_Liaotian,textView_Guanyu;
    private List <TextView>textViewList=new ArrayList<>();
    private int [] menu_Bc_a={R.drawable.menu_1_a,
            R.drawable.menu_1_b,
            R.drawable.menu_1_a,
            R.drawable.menu_1_b,
            R.drawable.menu_1_a
    };
    private int [] menu_Bc_b={R.drawable.menu_1_a,
            R.drawable.menu_1_b,
            R.drawable.menu_1_a,
            R.drawable.menu_1_b,
            R.drawable.menu_1_a
    };
    private HomeFragment homeFragment;
    private int showId=R.id.  menu_shouye;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        textView_Shouye=    (TextView) findViewById(R.id.  menu_shouye);
        textView_Zhuodan=   (TextView) findViewById(R.id.  menu_zhuodan);
        textView_Liaotian=  (TextView) findViewById(R.id.  menu_liaotian);
        textView_Guanyu=    (TextView) findViewById(R.id.  menu_guanyu);
        textViewList.add(textView_Shouye);//
        textViewList.add(textView_Zhuodan);//,
        textViewList.add(textView_Liaotian);//,
        textViewList.add(  textView_Guanyu);
        setTextViewOnClickListenter();
    }



    private void addFragmentToStack(Fragment fragment) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_in_left);
        ft.replace(R.id.fragment_container, fragment);
        ft.commit();
    }


    @Override
    public void onClick(View v) {
        if (showId==v.getId())
        {
            return;
        }
        switch (v.getId()){
            case (R.id.  menu_shouye  ):
                addFragmentToStack(new HomeFragment());
                break;
            case (R.id.  menu_zhuodan ):
                addFragmentToStack(new ZhuoDanFragment());
                break;
            case (R.id.  menu_liaotian):
                addFragmentToStack(new HomeFragment());
                break;
            case (R.id.  menu_guanyu  ):
                addFragmentToStack(new HomeFragment());
                break;
        }
        setTextViewBc(v);
        showId=v.getId();
    }

    private void setTextViewOnClickListenter(){
        for (TextView textView : textViewList) {
            textView.setOnClickListener(this);
        }
    }
    private void setTextViewBc(View view){

        for (int i = 0; i < textViewList.size(); i++) {
            TextView textView=textViewList.get(i);
            if (view.getId()==textView.getId()){
                Drawable drawablea = new BitmapDrawable(ImageUtil.readBitMap(this,menu_Bc_a[i]));
                drawablea.setBounds(0, 0, drawablea.getMinimumWidth(), drawablea.getMinimumHeight());
                textView.setTextColor(getResources().getColor(R.color.darkblue));
                textView.setCompoundDrawables(null,drawablea,null,null);
            }else {
                Drawable drawablea = new BitmapDrawable(ImageUtil.readBitMap(this,menu_Bc_a[i]));
                drawablea.setBounds(0, 0, drawablea.getMinimumWidth(), drawablea.getMinimumHeight());
                textView.setTextColor(getResources().getColor(R.color.darkorchid));
                textView.setCompoundDrawables(null,drawablea,null,null);
            }
        }

    }
}
